package services

import (
	"encoding/json"
	"gorm.io/gorm"
	"mygo/app/models"
	"strings"
)

func HandelWzhx(forecast *models.Forecast, time string, db *gorm.DB) {
	timeArr := strings.Split(time, "-")
	year := timeArr[0]
	month := timeArr[1]
	day := timeArr[2]
	timeNow := year + "-" + month + "-" + day
	var foreList models.ForeList
	db.Where("code = ?", "rahx").First(&foreList)
	var foreDetail models.ForeDetailJson
	db.Where("foreListId = ? AND time = ? AND state != ?", foreList.Id, timeNow, "0").First(&foreDetail)
	var raData = models.Forecast{}
	json.Unmarshal(foreDetail.Data, &raData)
	if len(raData.Reports) == 0 {
		return
	}
	for i, report := range forecast.Reports {
		if i == 0 {
			report.Data[1][1].Value = raData.Reports[0].Data[1][4].Value
			report.Data[1][2].Value = raData.Reports[0].Data[4][7].Value

			report.Data[2][1].Value = raData.Reports[0].Data[4][4].Value
			report.Data[2][2].Value = raData.Reports[0].Data[4][7].Value
		}
	}
}
